{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e62016ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series, DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b12592fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "products_df = DataFrame([{'product_id':23, 'name':'computer',\n",
    "                          'wholesale_price': 500,\n",
    "                          'retail_price':1000,\n",
    "                          'department':'electronics'},\n",
    "                        {'product_id':96, 'name':'Python Workout',\n",
    "                         'wholesale_price': 35,\n",
    "                         'retail_price':75, 'department':'books'},\n",
    "                        {'product_id':97, 'name':'Pandas Workout',\n",
    "                         'wholesale_price': 35,\n",
    "                         'retail_price':75, 'department':'books'},\n",
    "                        {'product_id':15, 'name':'banana',\n",
    "                         'wholesale_price': 0.5,\n",
    "                         'retail_price':1, 'department':'food'},\n",
    "                        {'product_id':87, 'name':'sandwich',\n",
    "                        'wholesale_price': 3,\n",
    "                         'retail_price':5, 'department': 'food'},\n",
    "                        ])\n",
    "\n",
    "sales_df = DataFrame([{'product_id': 23, 'date':'2021-August-10',\n",
    "                       'quantity':1},\n",
    "                     {'product_id': 96, 'date':'2021-August-10',\n",
    "                       'quantity':5},\n",
    "                     {'product_id': 15, 'date':'2021-August-10',\n",
    "                       'quantity':3},\n",
    "                     {'product_id': 87, 'date':'2021-August-10',\n",
    "                       'quantity':2},\n",
    "                     {'product_id': 15, 'date':'2021-August-11',\n",
    "                       'quantity':1},\n",
    "                     {'product_id': 96, 'date':'2021-August-11',\n",
    "                       'quantity':1},\n",
    "                     {'product_id': 23, 'date':'2021-August-11',\n",
    "                       'quantity':2},\n",
    "                     {'product_id': 87, 'date':'2021-August-12',\n",
    "                       'quantity':2},\n",
    "                     {'product_id': 97, 'date':'2021-August-12',\n",
    "                       'quantity':6},\n",
    "                     {'product_id': 97, 'date':'2021-August-12',\n",
    "                       'quantity':1},\n",
    "                     {'product_id': 87, 'date':'2021-August-13',\n",
    "                       'quantity':2},\n",
    "                     {'product_id': 23, 'date':'2021-August-13',\n",
    "                       'quantity':1},\n",
    "                     {'product_id': 15, 'date':'2021-August-14',\n",
    "                       'quantity':2}\n",
    "                     ])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "21c8bb01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>product_id</th>\n",
       "      <th>name</th>\n",
       "      <th>wholesale_price</th>\n",
       "      <th>retail_price</th>\n",
       "      <th>department</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23</td>\n",
       "      <td>computer</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>electronics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>96</td>\n",
       "      <td>Python Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>97</td>\n",
       "      <td>Pandas Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15</td>\n",
       "      <td>banana</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1</td>\n",
       "      <td>food</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>87</td>\n",
       "      <td>sandwich</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "      <td>food</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   product_id            name  wholesale_price  retail_price   department\n",
       "0          23        computer            500.0          1000  electronics\n",
       "1          96  Python Workout             35.0            75        books\n",
       "2          97  Pandas Workout             35.0            75        books\n",
       "3          15          banana              0.5             1         food\n",
       "4          87        sandwich              3.0             5         food"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "products_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4aff6b91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>product_id</th>\n",
       "      <th>date</th>\n",
       "      <th>quantity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>96</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>87</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>96</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>23</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>87</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>97</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>97</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>87</td>\n",
       "      <td>2021-August-13</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>23</td>\n",
       "      <td>2021-August-13</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>15</td>\n",
       "      <td>2021-August-14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    product_id            date  quantity\n",
       "0           23  2021-August-10         1\n",
       "1           96  2021-August-10         5\n",
       "2           15  2021-August-10         3\n",
       "3           87  2021-August-10         2\n",
       "4           15  2021-August-11         1\n",
       "5           96  2021-August-11         1\n",
       "6           23  2021-August-11         2\n",
       "7           87  2021-August-12         2\n",
       "8           97  2021-August-12         6\n",
       "9           97  2021-August-12         1\n",
       "10          87  2021-August-13         2\n",
       "11          23  2021-August-13         1\n",
       "12          15  2021-August-14         2"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sales_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4ce486f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "products_df = products_df.set_index('product_id')\n",
    "sales_df = sales_df.set_index('product_id')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "eb2e96d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>wholesale_price</th>\n",
       "      <th>retail_price</th>\n",
       "      <th>department</th>\n",
       "      <th>date</th>\n",
       "      <th>quantity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>product_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>banana</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>banana</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>banana</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>computer</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>electronics</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>computer</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>electronics</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>computer</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>electronics</td>\n",
       "      <td>2021-August-13</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>sandwich</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>sandwich</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>sandwich</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "      <td>food</td>\n",
       "      <td>2021-August-13</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>Python Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "      <td>2021-August-10</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>Python Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "      <td>2021-August-11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>Pandas Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>Pandas Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "      <td>2021-August-12</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      name  wholesale_price  retail_price   department  \\\n",
       "product_id                                                               \n",
       "15                  banana              0.5             1         food   \n",
       "15                  banana              0.5             1         food   \n",
       "15                  banana              0.5             1         food   \n",
       "23                computer            500.0          1000  electronics   \n",
       "23                computer            500.0          1000  electronics   \n",
       "23                computer            500.0          1000  electronics   \n",
       "87                sandwich              3.0             5         food   \n",
       "87                sandwich              3.0             5         food   \n",
       "87                sandwich              3.0             5         food   \n",
       "96          Python Workout             35.0            75        books   \n",
       "96          Python Workout             35.0            75        books   \n",
       "97          Pandas Workout             35.0            75        books   \n",
       "97          Pandas Workout             35.0            75        books   \n",
       "\n",
       "                      date  quantity  \n",
       "product_id                            \n",
       "15          2021-August-10         3  \n",
       "15          2021-August-11         1  \n",
       "15          2021-August-14         2  \n",
       "23          2021-August-10         1  \n",
       "23          2021-August-11         2  \n",
       "23          2021-August-13         1  \n",
       "87          2021-August-10         2  \n",
       "87          2021-August-12         2  \n",
       "87          2021-August-13         2  \n",
       "96          2021-August-10         5  \n",
       "96          2021-August-11         1  \n",
       "97          2021-August-12         6  \n",
       "97          2021-August-12         1  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "products_df.join(sales_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2b055897",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>wholesale_price</th>\n",
       "      <th>retail_price</th>\n",
       "      <th>department</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>product_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>computer</td>\n",
       "      <td>500.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>electronics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>Python Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>Pandas Workout</td>\n",
       "      <td>35.0</td>\n",
       "      <td>75</td>\n",
       "      <td>books</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>banana</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1</td>\n",
       "      <td>food</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>sandwich</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "      <td>food</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      name  wholesale_price  retail_price   department\n",
       "product_id                                                            \n",
       "23                computer            500.0          1000  electronics\n",
       "96          Python Workout             35.0            75        books\n",
       "97          Pandas Workout             35.0            75        books\n",
       "15                  banana              0.5             1         food\n",
       "87                sandwich              3.0             5         food"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "products_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bcaa45b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
